<template>
  <j-modal
    :title="'生成数据集'"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="formDisabled">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
             <a-col :span="24">
              <a-form-model-item label="槽号" :labelCol="labelCol" :wrapperCol="wrapperCol">
                {{model.slotNo}}
              </a-form-model-item>
            </a-col>
             <a-col :span="24">
              <a-form-model-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
                {{model.beginDate}}  至  {{model.endDate}}
              </a-form-model-item>
            </a-col> 
            <a-col :span="24">
              <a-form-model-item label="数据量" :labelCol="labelCol" :wrapperCol="wrapperCol">
                {{model.dataSize}}
              </a-form-model-item>
            </a-col> 
            <a-col :span="24">
              <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
                <a-input v-model="model.name" placeholder="请输入名称"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
                <a-textarea v-model="model.remark" rows="4" placeholder="请输入备注" />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'

export default {
  name: 'BuildModal',
  components: {},
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      model: {
        name: '',
        remark:'',
        dataSize: '',
        slotNo:'',
        beginDate:'',
        endDate:'',
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        name: [{ required: true, message: '请输入名称!' }],
      },
      url: {
        add: '/dataSet/dataSet/add',
      },
    }
  },
  methods: {
    add() {
      this.visible = true
    },
    edit(record) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.edit(record)
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          httpAction(this.url.add, this.model, 'post')
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
                that.visible = false
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>